package com.leyou.user.controller;

import com.leyou.user.pojo.UserDetail;
import com.leyou.user.service.UserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserDetailController {

    @Autowired
    private UserDetailService userDetailService;

    @GetMapping("detail/{id}")
    public ResponseEntity<List<UserDetail>> queryUserDetail(@PathVariable("id") Long userId){
        return ResponseEntity.ok(this.userDetailService.queryUserDetails(userId));
    }

    @PostMapping("address/{id}")
    public ResponseEntity<Void> addUserDetail(@RequestBody UserDetail userDetail, @PathVariable("id") Long userId){
        this.userDetailService.addUserDetail(userDetail, userId);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }
}
